﻿using System.ComponentModel.Composition;
using System.Waf.Applications;
using System.Windows.Controls;
using HighLandirect.Applications.ViewModels;
using HighLandirect.Applications.Views;
using HighLandirect.Domain;

namespace HighLandirect.Presentation.Views
{
    [Export(typeof(IOrderListView))]
    public partial class OrderListView : UserControl, IOrderListView
    {
        public OrderListView()
        {
            InitializeComponent();
        }


        private OrderListViewModel ViewModel { get { return DataContext as OrderListViewModel; } }


        private void ListViewSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
            foreach (object o in e.RemovedItems)
            {
                Order order = o as Order;
                if(order != null)
                    ViewModel.SelectedOrders.Remove(order);
            }
            foreach (object o in e.AddedItems)
            {
                Order order = o as Order;
                if (order != null)
                    ViewModel.SelectedOrders.Add(order);
            }
            
            //選択している顧客のOrderHistoryを出す
            if(e.AddedItems.Count > 0 && e.AddedItems[0] is Order)
                ViewModel.SendCustomerId = ((Order)e.AddedItems[0]).SendCustID.ToString();
        }

        private void SendStoreSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            /*
            foreach (Order order in e.RemovedItems)
            {
                ViewModel.SelectedOrders.Remove(order);
            }
            foreach (Order order in e.AddedItems)
            {
                ViewModel.SelectedOrders.Add(order);
            }
            */
        }

        private void OrderHistorySelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
            foreach (OrderHistory orderHistory in e.RemovedItems)
            {
                ViewModel.SelectedOrderHistories.Remove(orderHistory);
            }
            foreach (OrderHistory orderHistory in e.AddedItems)
            {
                ViewModel.SelectedOrderHistories.Add(orderHistory);
            }
            
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }
    }
}
